<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivityGroupTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //拼团活动表
        Schema::create('activity_group', function(Blueprint $table) {
            $table->increments('id')->comment('自增id');
            $table->integer('goods_id')->default(0)->comment('商品id');
            $table->integer('goods_spu_id')->default(0)->comment('商品属性id');
            $table->decimal('single_money')->default(0)->comment('单人活动价');
            $table->decimal('many_money')->default(0)->comment('拼团活动价');
            $table->integer('max_group_num')->default(0)->comment('最大拼团人数');
            $table->timestamp('start_time')->nullable()->comment('活动开始时间');
            $table->timestamp('end_time')->nullable()->comment('活动结束时间');
            $table->integer('group_effective_time')->default(0)->comment('拼团有效时间（小时）');
            $table->integer('sort')->default(0)->comment('排序');
            $table->integer('status')->default(0)->comment('状态：0：下架 1：上架');
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::table('orders', function (Blueprint $table) {

            $table->integer('activity_id')->default(0)->comment('活动id  包括砍价活动和拼团活动')->after('type');
            $table->integer('group_type')->default(0)->comment('拼团类型 1：单独购买 2：发起拼团 3：参加拼团')->after('activity_id');
            $table->integer('group_refund')->default(0)->comment('是否退款 0：未退款 1：已退款 2：退款失败')->after('group_type');


        });

        //参与拼团活动表
        Schema::create('activity_group_add', function(Blueprint $table) {
            $table->increments('id')->comment('自增id');
            $table->integer('user_id')->default(0)->comment('用户id');
            $table->string('order_num')->nullable()->comment('订单编号');
            $table->integer('ag_id')->default(0)->comment('活动id');
            $table->integer('group_num')->default(0)->comment('实际拼团人数');
            $table->timestamp('start_time')->nullable()->comment('活动开始时间');
            $table->timestamp('end_time')->nullable()->comment('活动结束时间');
            $table->integer('status')->default(0)->comment('状态 0：进行中 1：拼团成功 2：拼团失败 3：退出拼团');
            $table->softDeletes();
            $table->timestamps();
        });

        //拼团退款表
        Schema::create('activity_group_refund', function(Blueprint $table) {
            $table->increments('id')->comment('自增id');
            $table->integer('user_id')->default(0)->comment('用户id');
            $table->string('order_num')->nullable()->comment('订单编号');
            $table->string('reason')->nullable()->comment('退款原因');
            $table->timestamp('cancel_group')->nullable()->comment('取消拼团的时间');
            $table->timestamp('refund_time')->nullable()->comment('退款时间');
            $table->integer('status')->default(0)->comment('状态 0：退款中 1：已退款 2：退款失败');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
